//
//  FQDAccountInputField.m
//  FakeQDaily
//
//  Created by mewxiv on 9/6/16.
//  Copyright © 2016 Xensius. All rights reserved.
//

#import "FQDAccountInputField.h"

#import "Masonry.h"

@implementation FQDAccountInputField

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self prepareUI];
        [self prepareConstraints];
    }
    return self;
}

- (void)prepareUI
{
    _textField = [[UITextField alloc] init];
    _textField.font = FQDRegularFontWithSize(14.0f);
    _textField.textColor = [UIColor whiteColor];
    [self addSubview:_textField];
    
    _separateLine = [[UIView alloc] init];
    _separateLine.backgroundColor = [UIColor colorWithWhite:1.0f alpha:0.2f];
    [self addSubview:_separateLine];
}

- (void)prepareConstraints
{
    WeakSelf;
    [_textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.and.left.equalTo(weakSelf).offset(10);
        make.bottom.and.right.equalTo(weakSelf).offset(-10);
    }];
    
    [_separateLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf).offset(8);
        make.width.equalTo(weakSelf).offset(-8);
        make.top.equalTo(weakSelf.mas_bottom);
        make.height.equalTo(@0.5);
    }];
}

- (void)setPlaceHolderString:(NSString *)placeHolderString
{
    NSDictionary *placeHolderAttrs = @{
        NSForegroundColorAttributeName : [UIColor colorWithWhite:1.0f alpha:0.6f],
    };
    
    NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:placeHolderString];
    [attrString setAttributes:placeHolderAttrs range:NSMakeRange(0, [placeHolderString length])];
    self.textField.attributedPlaceholder = attrString;
}

@end
